package j2metris.pieces;

import j2metris.Coordinate;
import j2metris.util.LoopingList;

abstract class StandardPieceThatIsNotO extends StandardPiece
{
    public abstract Coordinate[][] getRotationStates();
    protected final LoopingList rotationStateList;

    public StandardPieceThatIsNotO()
    {
        rotationStateList = new LoopingList(getRotationStates());
    }

    public StandardPieceThatIsNotO(int rotationState)
    {
        rotationStateList = new LoopingList(getRotationStates(), rotationState);
    }

    public void rotateClockwise()
    {
        rotationStateList.increment(1);
    }

    public void rotateCounterclockwise()
    {
        rotationStateList.increment(-1);
    }

    public Coordinate[] getRotationState()
    {
        Coordinate[] retCopy = (Coordinate[]) rotationStateList.getCurrentObject();
        Coordinate[] ret = new Coordinate[retCopy.length];
        for(int i = 0; i < ret.length; ++i)
        {
            ret[i] = retCopy[i];
        }
        return ret;
    }

    public Coordinate[] getRotationState(int distanceFromCurrentState)
    {
        Coordinate[] retCopy = (Coordinate[]) rotationStateList.getObject(distanceFromCurrentState);
        Coordinate[] ret = new Coordinate[retCopy.length];
        for(int i = 0; i < ret.length; ++i)
        {
            ret[i] = retCopy[i];
        }
        return ret;
    }
}
